package com.ithzl.capacity.mapper;

import com.ithzl.capacity.pojo.User;
import com.ithzl.capacity.pojo.dto.UserPageDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    /**
     * 按账号获取用户
     * @param number
     * @return
     */
    @Select("select * from user where accession_number=#{number}")
    User getUserByAccessionNumber(@Param("number") String number);

    /**
     * 按id修改密码
     * @param id
     * @param password
     * @return
     */
    @Update("update user set password=#{password} where id=#{id}")
    void updatePasswordById(@Param("id") int id,@Param("password") String password);

    /**
     * 查询用户列表
     * @param userPageDTO
     * @return
     */
    List<User> selectUserList(@Param("userPageDTO") UserPageDTO userPageDTO);

    /**
     * 新增账号
     * @param user
     */
    @Insert("insert into user(name, school, accession_number, password, identity, scope)" +
            " values (#{user.name},#{user.school},#{user.accessionNumber},#{user.password},#{user.identity},#{user.scope})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void addUser(@Param("user") User user);

    /**
     * 账号修改
     * @param user
     */
    @Update("update user set " +
            "    name=#{user.name}," +
            "    school=#{user.school}," +
            "    accession_number=#{user.accessionNumber}," +
            "    identity=#{user.identity}," +
            "    scope=#{user.scope} " +
            "where id=#{user.id} ")
    void update(@Param("user") User user);

    /**
     * 删除用户
     * @param id
     */
    @Delete("delete from user where id=#{id}")
    void delete(@Param("id") int id);
}
